//
//  LoginBaseViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/2/7.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "LoginBaseViewController.h"
#import "OpenInstallSDK.h"
#import "LoginModel.h"

@interface LoginBaseViewController ()

@end

@implementation LoginBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加视频界面
    [self addVideoView];

    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.movieController prepareToPlay];
    [self getInstallParamsImmediately];
}

-(void)getInstallParamsImmediately{

    [[OpenInstallSDK defaultManager] getInstallParmsCompleted:^(OpeninstallData*_Nullable appData) {
    
            if (appData.data) {//(动态安装参数)
                   //e.g.如免填邀请码建立邀请关系、自动加好友、自动进入某个群组或房间等
               }
           if (appData.channelCode) {//(通过渠道链接或二维码安装会返回渠道编号)
                   //e.g.可自己统计渠道相关数据等
               }
//        NSString *parameter = [NSString stringWithFormat:@"如果没有任何参数返回，请确认：\n1、新应用是否上传安装包(是否集成完毕)  2、是否正确配置appKey  3、是否通过含有动态参数的分享链接(或二维码)安装的app\n\n动态参数：\n%@\n渠道编号：%@",appData.data,appData.channelCode];
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"安装参数" message:parameter delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alert show];
        
            [LoginModel sharedLoginModel].invite_code = SafeStr([appData.data valueForKey:@"invite_code"]);
        NSLog(@"%@", [LoginModel sharedLoginModel].invite_code);
        NSLog(@"dsf");
        
        }];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.movieController stop];

}

//添加视频
-(void)addVideoView
{
    [self setVieo];
}

-(void)setVieo
{
    NSString *videoPath=[[NSBundle mainBundle]pathForResource:@"loginVideo" ofType:@"mp4"];
    self.movieController=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
    self.movieController.scalingMode=MPMovieScalingModeAspectFill;
    [self.view addSubview:self.movieController.view];
    //添加模糊层
    UIView *view = [[UIView alloc] init];
    view.frame = self.view.bounds;
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    [self.view addSubview:view];
    [self.view sendSubviewToBack:self.movieController.view];
    self.movieController.view.frame = self.view.bounds;
    [self.movieController setControlStyle:MPMovieControlStyleNone];      //去掉进度条
    [self.movieController setShouldAutoplay:YES];
    [self.movieController setRepeatMode:MPMovieRepeatModeOne];
    [self.movieController prepareToPlay];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
